package org.geektimes.projects.user.web.controller;

import org.geektimes.projects.user.domain.User;
import org.geektimes.projects.user.service.UserService;
import org.geektimes.projects.user.service.impl.UserServiceImpl;
import org.geektimes.web.mvc.controller.PageController;
import org.geektimes.web.mvc.controller.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;

/**
 * 输出 “Hello,World” Controller
 */
@Path("/register")
public class RegisterSaveController implements RestController {


    @POST
    @Override
    @Path("/save")
    public String execute(HttpServletRequest request, HttpServletResponse response) throws Throwable {

        //获取参数的值
        String userName = request.getParameter("username");
        String passWord = request.getParameter("password");
        String email = request.getParameter("email");
        String phoneNumber = request.getParameter("phoneNumber");

        User user = new User();
        user.setName(userName);
        user.setPassword(passWord);
        user.setEmail(email);
        user.setPhoneNumber(phoneNumber);

        UserService userService = new UserServiceImpl();
        userService.register(user);

        return "{\"name\":\"tongxing\"}";
    }




}
